﻿using System;
using System.Windows.Forms;
using Data.Common;
using Data.Enum;
using Data.Model;
using DataAccess.AccountManage;
using Ninject;
using WinForm.Helper;

namespace WinForm.UserManage
{
    public partial class FrmAction : Form
    {
        private static readonly IKernel Kernel = new StandardKernel(new DbModule());
        private readonly IAccount _account = Kernel.Get<IAccount>();

        public FrmAction()
        {
            InitializeComponent();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            string errorMessage = string.Empty;
            try
            {
                string status = string.Empty;
                if (radioButton1.Checked)
                {
                    status = radioButton1.Text;
                }
                if (radioButton2.Checked)
                {
                    status = radioButton2.Text;
                }
                if (radioButton3.Checked)
                {
                    status = radioButton3.Text;
                }
                if (radioButton4.Checked)
                {
                    status = radioButton4.Text;
                }
                if (string.IsNullOrEmpty(status))
                {
                    errorMessage = errorMessage + "请选择需要更改的类型";
                }
                else
                {
                    ResultInfo<jsh_account> account = _account.GetAccountWithIdCard(textBox1.Text);
                    if (account.ResultNumber == ResultEnum.Success)
                    {
                        ResultInfo<bool> us = _account.UpdateAccountStatus(account.Obj.id, status);
                        if (us.ResultNumber == ResultEnum.Success)
                        {
                            errorMessage = "更新成功";
                        }
                        else
                        {
                            errorMessage = errorMessage + us.Describe;
                        }
                    }
                    else
                    {
                        errorMessage = errorMessage + account.Describe;
                    }
                }
            }
            catch (Exception e1)
            {
                errorMessage = errorMessage + e1.Message;
            }
            if (!string.IsNullOrEmpty(errorMessage))
            {
                MyMessageBox.ShowMessageBoxError(errorMessage);
            }
        }
    }
}
